package com.ruoyi.project.sdi.sdiDocDefine.controller;

import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.sdi.sdiDocDefine.domain.SdiDocDefine;
import com.ruoyi.project.sdi.sdiDocDefine.service.ISdiDocDefineService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import java.util.Arrays;

import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 票据类型Controller
 *
 * @author XQ.XU
 * @date 2020-03-20
 */
@Controller
@RequestMapping("/sdi/sdiDocDefine")
public class SdiDocDefineController extends BaseController
{
    private String prefix = "sdi/sdiDocDefine";

    @Autowired
    private ISdiDocDefineService sdiDocDefineService;

    @RequiresPermissions("sdi:sdiDocDefine:view")
    @GetMapping()
    public String sdiDocDefine()
    {
        return prefix + "/sdiDocDefine";
    }

    /**
     * 查询票据类型列表
     */
    @RequiresPermissions("sdi:sdiDocDefine:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SdiDocDefine sdiDocDefine)
    {
        startPage();
        List<SdiDocDefine> list = sdiDocDefineService.list(new QueryWrapper<>(sdiDocDefine));
        return getDataTable(list);
    }

    /**
     * 导出票据类型列表
     */
    @RequiresPermissions("sdi:sdiDocDefine:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SdiDocDefine sdiDocDefine)
    {
        List<SdiDocDefine> list = sdiDocDefineService.list(new QueryWrapper<>(sdiDocDefine));
        ExcelUtil<SdiDocDefine> util = new ExcelUtil<SdiDocDefine>(SdiDocDefine.class);
        return util.exportExcel(list, "sdiDocDefine");
    }

    /**
     * 新增票据类型
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存票据类型
     */
    @RequiresPermissions("sdi:sdiDocDefine:add")
    @Log(title = "票据类型", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SdiDocDefine sdiDocDefine)
    {
        return toAjax(sdiDocDefineService.saveOrUpdate(sdiDocDefine));
    }

    /**
     * 修改票据类型
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        SdiDocDefine sdiDocDefine = sdiDocDefineService.getById(id);
        mmap.put("sdiDocDefine", sdiDocDefine);
        return prefix + "/edit";
    }

    /**
     * 修改保存票据类型
     */
    @RequiresPermissions("sdi:sdiDocDefine:edit")
    @Log(title = "票据类型", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SdiDocDefine sdiDocDefine)
    {
        return toAjax(sdiDocDefineService.saveOrUpdate(sdiDocDefine));
    }

    /**
     * 删除票据类型
     */
    @RequiresPermissions("sdi:sdiDocDefine:remove")
    @Log(title = "票据类型", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sdiDocDefineService.removeByIds(Arrays.asList(ids.split(","))));
    }
}
